package cn.tedu.service.impl;

import cn.tedu.mapper.UserMapper;
import cn.tedu.pojo.User;
import cn.tedu.pojo.UserExample;
import cn.tedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public boolean register(User user) {
        try {
            return userMapper.insertSelective(user)==1;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public boolean login(User user) {
        try {
            UserExample userExample = new UserExample();
            userExample.createCriteria().andUsernameEqualTo(user.getUsername()).andPasswordEqualTo(user.getPassword());
            List<User> users = userMapper.selectByExample(userExample);
            return users.size()==1;
        }catch (Exception e){
            return false;
        }
    }
}
